function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


google.load('visualization', '1', {packages: ['corechart']});

$(document).ready(function(){

	var dateFormat=function(){var a=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,b=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,c=/[^-+\dA-Z]/g,d=function(a,b){a=String(a);b=b||2;while(a.length<b)a="0"+a;return a};return function(e,f,g){var h=dateFormat;if(arguments.length==1&&Object.prototype.toString.call(e)=="[object String]"&&!/\d/.test(e)){f=e;e=undefined}e=e?new Date(e):new Date;if(isNaN(e))throw SyntaxError("invalid date");f=String(h.masks[f]||f||h.masks["default"]);if(f.slice(0,4)=="UTC:"){f=f.slice(4);g=true}var i=g?"getUTC":"get",j=e[i+"Date"](),k=e[i+"Day"](),l=e[i+"Month"](),m=e[i+"FullYear"](),n=e[i+"Hours"](),o=e[i+"Minutes"](),p=e[i+"Seconds"](),q=e[i+"Milliseconds"](),r=g?0:e.getTimezoneOffset(),s={d:j,dd:d(j),ddd:h.i18n.dayNames[k],dddd:h.i18n.dayNames[k+7],m:l+1,mm:d(l+1),mmm:h.i18n.monthNames[l],mmmm:h.i18n.monthNames[l+12],yy:String(m).slice(2),yyyy:m,h:n%12||12,hh:d(n%12||12),H:n,HH:d(n),M:o,MM:d(o),s:p,ss:d(p),l:d(q,3),L:d(q>99?Math.round(q/10):q),t:n<12?"a":"p",tt:n<12?"am":"pm",T:n<12?"A":"P",TT:n<12?"AM":"PM",Z:g?"UTC":(String(e).match(b)||[""]).pop().replace(c,""),o:(r>0?"-":"+")+d(Math.floor(Math.abs(r)/60)*100+Math.abs(r)%60,4),S:["th","st","nd","rd"][j%10>3?0:(j%100-j%10!=10)*j%10]};return f.replace(a,function(a){return a in s?s[a]:a.slice(1,a.length-1)})}}();dateFormat.masks={"default":"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"};dateFormat.i18n={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]};Date.prototype.format=function(a,b){return dateFormat(this,a,b)}

	var INI = this;

	// scrollto
	$('#scrollto').click(function(e){
		e.preventDefault();
		$('body, html').animate({ scrollTop: $('.main_in').offset().top - 20 }, 200);
	});
	$(window).scroll(function(){
		var sT = $(window).scrollTop(), wH = $(window).height();
		if( (0.35 * wH) <= sT ){
			$('#scrollto').fadeIn();
		}else{
			$('#scrollto').fadeOut();
		}
	});
	
	// dropdown
	$('.expanded').hover(function(){
		$(this).toggleClass('active')
			.find('.menu')
			.slideToggle(150);
	});
	if( $('#msg_postform').html()!="" && !$('#msg_postform').is(":visible") ){
		$('#msg_postform').show();
		window.setTimeout(function(){ $('#msg_postform').fadeOut(800) }, 10000);
	}
	
	// create fixed layer
	$("body").append( $('<div id="lyr_ldr" class="fixdiv" style="display:none;"><div class="fixed_text fx_saving" id="fixed_msg"></div></div>') );
	
	
	function g(x){return document.getElementById(x)}
	
	function loader_toggle(mode){
		if( !g('gloader') ){
			var imgsrc = "";
				+ ""
				+ "wEAAAAh+QQFAAAIACwAAAAACwALAAAEJBBJaeYMs8pz6bYIVnFgKQEoMBVsYZoCQiADGMtSLd14Xs6WCAAh+QQFAAAIACwAAAAACwALAAAEJBBJGeYEs0pz6bYIV"
				+ "nFgKQmoMB3sYZoEMiAFGMtSLd14Xs6WCAAh+QQFAAAIACwAAAAACwALAAAEJBBJCeYUs8pw6bYIVnFgKREoMRmsYZoDUiAHGMtSLd14Xs6WCAAh+QQFAAAIACwAA"
				+ "AAACwALAAAEJBBJKeYks0pw6bYIVnFgKQ3oMAVsYJoFciAGGMtSLd14Xs6WCAAh+QQFAAAIACwAAAAACwALAAAEJBBJSeYcs0px6bYIVnFgKRVoMQEsYJoHYiABG"
				+ "MtSLd14Xs6WCAAh+QQFAAAIACwAAAAACwALAAAEJBBJOeYss0py6bYIVnFgKR3oMQmsYJoGEiAAGMtSLd14Xs6WCAAh+QQFAAAIACwAAAAACwALAAAEJBBJWeY8s"
				+ "8px6bYIVnFgKRmoMREsYZoBAiACGMtSLd14Xs6WCAAh+QQFAAAIACwAAAAACwALAAAEJBBJeeY0s8py6bYIVnFgKQVoMA3sYJoAIiAEGMtSLd14Xs6WCAA7";

			$('#chart_content').html('<div id="gloader"/>');
			$('#gloader').append('<img src="'+imgsrc+'"/>');
		}else{
			if("undefined" != mode){
				if(mode)
					$('#gloader').show();
				else
					$('#gloader').hide();
			}else{
				var cur = $('#gloader').css('display');
				cur = (cur == 'none');
				$('#gloader').css('display', (cur ? '':'none'));
			}
		}
	}
	
	
	function findMeParent(o, tipe){
		// goup specific parent
		var par, got = false, maxlop=5, i=0;
		par = $(o);
		while(!got && i<maxlop){
			if(par.get(0).nodeName != tipe){
				par = par.parent(); i++;
			}else{
				got = true; break;
			}
		}
		return (got ? par : false);
	}
	
	
	// buka-buka(an) btn_buka ..
	$('.btn_buka').click(function(){
		$('#'+$(this).attr('id').replace(/_button/,'') ).slideToggle('fast', function(){
			g( $(this).attr('id')+'_button' ).setAttribute('value', ($(this).css('display')!='none' ? 'Hide' : 'Show') );
		});
	})
	
	// btn penutup apibox,. tungning nungning..
	$('.ctutup').click(function(){
		var got = findMeParent($(this), 'LI');
		if(got && $(got).find('.apibox').css('display')!='none' )
			$(got).find('.btn_buka').click();
	});
	
	$('.ctutupall').click(function(){
		$('.ctutup').each(function(){ $(this).click() });
	});
	
	
});

